home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / wexmast / wtoggle.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  94 lines

  1. ; $Id: wtoggle.pro,v 1.3 1997/01/15 04:29:15 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ; This is the code for a simple set of toggle button widgets.
  7. ; A set of toggle buttons acts like an ON-OFF switch.
  8. ; In this example, when the ON button is selected, the 
  9. ; variable 'value' is set equal to 1.  When the OFF button is
  10. ; selected, the variable 'value' is set equal to 0.
  11.  
  12. ; For an example of toggle buttons in action, see the routine
  13. ; WORLDROT.PRO where they are used to turn certain drawing
  14. ; and display features on or off.
  15.  
  16.  
  17.  
  18.  
  19. PRO wtoggle_event, event
  20. ; This is the code for a simple 2-button toggle switch.
  21.  
  22. ; Both procedures need to know about the variable 'value':
  23.  
  24. COMMON wtoggleblock, value
  25.  
  26. ; Put the UVALUE of any widget touched into the variable 'eventval':
  27. WIDGET_CONTROL, event.id, GET_UVALUE = eventval
  28.  
  29. ; A CASE statement is an easy way to handle toggle buttons:
  30. CASE eventval OF
  31.     "ON":    BEGIN            ; The ON button has been pressed.
  32.              value = 1
  33.         PRINT, 'value = ', value
  34.         END
  35.  
  36.     "OFF":    BEGIN            ; The OFF button has been pressed.
  37.         value = 0
  38.         PRINT, 'value = ', value
  39.         END
  40. ENDCASE
  41.  
  42. END
  43.  
  44.  
  45.  
  46. PRO wtoggle, GROUP = GROUP
  47.  
  48. ; Both procedures need to know about the variable 'on':
  49.  
  50. COMMON wtoggleblock, value
  51.  
  52. ; Make the main base:
  53. base = WIDGET_BASE(TITLE = 'Toggle Buttons Example', /COLUMN, XSIZE = 300)
  54.  
  55. ; Make another base to hold the exclusive buttons.  The base is made
  56. ; capable of holding only exclusive buttons so that when the ON button
  57. ; is selected, the OFF button is automatically de-selected and vice
  58. ; versa:
  59.  
  60. togglebase = WIDGET_BASE(base, /COLUMN, /FRAME, /EXCLUSIVE)
  61.  
  62. ; Make the ON button:
  63. onbutton = WIDGET_BUTTON(togglebase, $    
  64.              VALUE='ON Button', $    ;The label for the button.
  65.              UVALUE='ON', $        ;The User Value for the button.
  66.              /NO_RELEASE)        ;The /NO_RELEASE keyword keeps
  67.                         ;the released button from
  68.                         ;generating an event when a new
  69.                         ;button is selected.
  70.  
  71. ; Make the OFF button:
  72. offbutton = WIDGET_BUTTON(togglebase, $
  73.               VALUE='OFF Button', $    ;The label for the button.
  74.               UVALUE='OFF', $    ;The User Value for the button.
  75.               /NO_RELEASE)        ;The /NO_RELEASE keyword keeps
  76.                         ;the released button from 
  77.                         ;generating an event when a new
  78.                         ;button is selected.
  79.  
  80.  
  81. ; Realize the widgets:
  82. WIDGET_CONTROL, base, /REALIZE
  83.  
  84. ; Initialize the ON button to be 'pushed in'. An associated variable, called
  85. ; 'on' is set to 1 when ON is selected and 0 when OFF is selected:    
  86.  
  87. WIDGET_CONTROL, onbutton, /SET_BUTTON
  88. value = 1
  89.  
  90. ; Hand off to the XManager:
  91. XMANAGER, 'wtoggle', base, GROUP_LEADER = GROUP, /NO_BLOCK
  92.  
  93. END
  94.